package charts.series.bars; 

import flash.geom.Point;

class Stack extends ElementBase {
	
	var total:Float;
	
	public function new( index:Float, style:Dynamic, group:Float ) {
		
		// we are not passed a string value, the value
		// is set by the parent collection later
		this.total =  style.total;
		super(index, style, style.colour, style.tip, style.alpha, group);
	}

//	override function replace_magic_values( t:String ): String {
	function replace_magic_values( t:String ): String {
		
		t = super.replace_magic_values(t);
		t =  StringTools.replace(t,'#total#', NumberUtils.formatNumber( this.total ));
		
		return t;
	}
	
	public function replace_x_axis_label( t:String ): Void {
		
		this.tooltip =  StringTools.replace(this.tooltip,'#x_label#', t );
	}
			
	//
	// BUG: we assume that all are positive numbers:
	//
	public override function resize( sc:ScreenCoordsBase ):Void {
		this.graphics.clear();
		
		var sc2:ScreenCoords = cast( sc, ScreenCoords);
		
		var tmp:Dynamic = sc2.get_bar_coords( this.index, this.group );
		
		// move the Sprite Into position:
		this.x = tmp.x;
		this.y = sc.get_y_from_val( this.top, this.right_axis );
		
		var height:Int = sc.get_y_from_val( this.bottom, this.right_axis) - this.y;

		this.graphics.beginFill( this.colour, 1 );
		this.graphics.drawRect( 0, 0, tmp.width, height );
		this.graphics.endFill();
		
		this.tip_pos = new flash.geom.Point( this.x + (tmp.width / 2), this.y );
	}
}
